package com.example.g2daylx2.bvm

import androidx.lifecycle.viewModelScope
import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.example.g2daylx2.fg.one.CarDataSource
import com.example.lib_base.net.ApiService
import com.example.lib_base.net.entity.CarEntityResultItem
import com.example.lib_base.net.mvvm.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class CarViewModel @Inject constructor(val apiService: ApiService):BaseViewModel() {
    fun getCar(type:String):Flow<PagingData<CarEntityResultItem>>{
        return Pager(config = PagingConfig(pageSize = 10), pagingSourceFactory = {
            CarDataSource(apiService,type)
        }).flow.cachedIn(viewModelScope)
    }
}